<template>
  <div>
    <CustomTable
      ref="table"
      :showAlert="false"
      :showSelection="false"
      :columns="blxwjlColumns"
      :loading="load"
      @change="onTableChange"
      :dataSource="pageData"
      :style="{ marginTop:'10px', height: '540px' }"
    >
      <template slot="xh" slot-scope="text, record, index">
        {{((pageFilter.pageNo - 1) * pageFilter.pageSize +(index + 1))>9?(pageFilter.pageNo - 1) * pageFilter.pageSize +(index + 1) :'0' + (index + 1) }}
      </template>
      <template slot="dealTime" slot-scope="record">
        <span v-if="record!=='' && record!==null">{{ moment(record).format("YYYY-MM-DD") }}</span>
      </template>
       <template slot="fileAction" slot-scope="text, record">
        <span v-if="record.file==null || record.file==''"></span>
        <template v-else v-for="(item,index) in JSON.parse(record.file)">
          <div :key="index" style="margin-bottom:5px;display:flex" >
            <div style="width: 85%;">{{item.name}}</div>  <a @click="downloadPDf(item)" >下载</a>
           </div>
        </template>
      </template>
    </CustomTable>
  </div>
</template>

<script>
import api from '@/api/index'
import download from 'downloadjs'; // 引用插件
export default {
  props: {
    ryid:{
      type:String
    },
  },
  data() {
    return {
      load: false,
      blxwjlColumns:[
            {
              title: '序号',
              dataIndex: 'xh',
              key: 'xh',
              width:60,
              scopedSlots: { customRender: "xh" }
            },
            {
              title: '处理主要内容',
              dataIndex: 'dealZynr',
              key: 'dealZynr',
              // ellipsis: true,
            },
            {
              title: '处理结果',
              dataIndex: 'dealJg',
              key: 'dealJg',
              // ellipsis: true,
            },
            {
              title: '处理机关',
              dataIndex: 'dealOffice',
              key: 'dealOffice',
              // ellipsis: true,
            },
            {
              title: '相关文号',
              dataIndex: 'relativeWh',
              key: 'relativeWh',
              // ellipsis: true,
            },
            {
              title: '处理时间',
              dataIndex: 'dealTime',
              key: 'dealTime',
              // ellipsis: true,
              scopedSlots: { customRender: "dealTime" }
            },
            {
              title: '有效期',
              dataIndex: 'exeTime',
              key: 'exeTime',
              // ellipsis: true,
            },
            {
              title: '附件',
              dataIndex: 'fileAction',
              key: 'file',
              width:250,
              scopedSlots: { customRender: "fileAction" }
            },
            
         ],
        pageData: [],
        pageFilter: {
          pageNo: 1,
          pageSize: 10,
          isPass:true,
        },
    };
  },
  created() {
    this.pageFilter.ryid = this.ryid;
    this.refreshTable();
  },
  methods: {
    onTableChange(pageFilter) {
      this.pageFilter = { ...this.pageFilter, ...pageFilter };
      this.refreshTable();
    },
    refreshTable() {
        this.load = true;
        api.get_ryxx_bljl_list(this.pageFilter) .then(res => {
          let pageNo = this.pageFilter.pageNo;
          let pageSize = this.pageFilter.pageSize;
          let records = res.rows;
          let total = res.total;
          this.pageData = {
            ...this.pageData,
            pageNo,
            records,
            pageSize,
            total
          };
          this.load = false;
            
        })
        .catch(err => {
          this.load = false;
        });


      },
      downloadPDf(item){
        download("/api"+item.path); 
      }
  }
};
</script>

<style lang="less">
</style>